package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangyu
 * @data 2023/4/20 16:40
 */
@RestController
@RequestMapping("/admin/setmeal")
@Api("套餐相关接口")
public class SetMealController {
    @Autowired
    private SetMealService setMealService;
    @PostMapping
    @ApiOperation("新增套餐")
    @CacheEvict(cacheNames = "setmealCach",key = "#setmealDTO.categoryId")
    public Result<String> addSetMeal(@RequestBody SetmealDTO setmealDTO){
            setMealService.addSetMeal(setmealDTO);
            return Result.success();
    }
    /**
     * 套餐分页条件查询
     */
    @GetMapping("/page")
    @ApiOperation("套餐分页条件查询")
    public Result<PageResult> pageSelectSetMeal(SetmealPageQueryDTO setmealPageQueryDTO){
     return Result.success(setMealService.pageSelectSetMeal(setmealPageQueryDTO));

    }
    /**
     * 删除套餐
     */
    @DeleteMapping
    @ApiOperation("删除套餐")
    @CacheEvict(cacheNames = "setmealCach",allEntries = true)
    public Result<String> deleteSetMealByIds(@RequestParam List<Long> ids){
            setMealService.deleteSetMeal(ids);
            return Result.success();
    }
    /**
     * 根据套餐id回显套餐信息
     */
    @GetMapping("/{id}")
    @ApiOperation("根据套餐id查询套餐信息")
    public Result<SetmealVO> selectSetMealById(@PathVariable Long id){
        return Result.success(setMealService.selectSetMealByIds(id));
    }
    /**
     * 根据套餐id修改套餐
     */
    @PutMapping
    @ApiOperation("根据套餐id修改套餐")
    @CacheEvict(cacheNames = "setmealCach",allEntries = true)
    public Result<String> updateSetMealInforMationById(@RequestBody SetmealDTO setmealDTO){
        setMealService.updateSetMeal(setmealDTO);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("套餐起售停售")
    @CacheEvict(cacheNames = "setmealCach",allEntries = true)
    public Result startOrStop(@PathVariable Integer status, Long id) {
        setMealService.startOrStop(status, id);
        return Result.success();
    }


}
